home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 124 / cd-rom 124.iso / edu / tuxmath / tuxmathscrabble / asymptopia / myutil.py < prev    next >
Encoding:
Python Source  |  2003-07-26  |  2.1 KB  |  65 lines

  1. """
  2. /***************************************************************************
  3.  
  4.     Author             :Charles B. Cosse 
  5.     
  6.     Email            :ccosse@asymptopia.com
  7.                     
  8.                     
  9.     Copyright        :(C) 2002,2003 Asymptopia Software.
  10.     
  11.  ***************************************************************************/
  12. /***************************************************************************
  13.                          myutil.py
  14.  
  15.  ***************************************************************************/
  16.  
  17. /***************************************************************************
  18.  *                                                                         *
  19.  *   This program is free software; you can redistribute it and/or modify  *
  20.  *   it under the terms of the GNU General Public License as published by  *
  21.  *   the Free Software Foundation; either version 2 of the License, or     *
  22.  *   (at your option) any later version. (Please note that if you use this *
  23.  *   code you must give credit by including the Author and Copyright       *
  24.  *   info at the top of this file).                                        *
  25.  ***************************************************************************/
  26. """
  27.  
  28. import pygame,os,sys
  29. from pygame.locals import *
  30.  
  31. #get path to site-packages:
  32. try:
  33.     for sitepkgdir in sys.path:
  34.         if sitepkgdir[-13:]=='site-packages':break
  35. except:pass
  36.     
  37.  
  38. def load_image(name, colorkey=None):
  39.     fullname = os.path.join(sitepkgdir,name)
  40.     try:
  41.         image = pygame.image.load(fullname)
  42.     except pygame.error, message:
  43.         print 'Cannot load image:', name
  44.         raise SystemExit, message
  45.     image = image.convert()
  46.     if colorkey is not None:
  47.         if colorkey is -1:
  48.             colorkey = image.get_at((0,0))
  49.         image.set_colorkey(colorkey, RLEACCEL)
  50.     return image, image.get_rect()
  51.            
  52. def load_sound(name):
  53.     class NoneSound:
  54.         def play(self): pass
  55.     if not pygame.mixer or not pygame.mixer.get_init():
  56.         return NoneSound()
  57.     fullname = os.path.join(sitepkgdir, name)
  58.     try:
  59.         sound = pygame.mixer.Sound(fullname)
  60.     except pygame.error, message:
  61.         print 'Cannot load sound:', fullname
  62.         raise SystemExit, message
  63.     return sound
  64.  
  65.